package com.toocms.jinjuhang.ui.mine.payment

import androidx.databinding.ObservableBoolean
import com.toocms.jinjuhang.config.Constants
import com.toocms.jinjuhang.config.PaymentType
import com.toocms.tab.base.ItemViewModel
import com.toocms.tab.binding.command.BindingAction
import com.toocms.tab.binding.command.BindingCommand
import com.toocms.tab.bus.Messenger

/**
 * @Description:
 * @Author:         Zero
 * @CreateDate:     2023/5/18 10:51
 */
class PaymentItemModel(viewModel: PaymentModel, type: PaymentType) :
    ItemViewModel<PaymentModel>(viewModel) {

    val isSelected = ObservableBoolean()

    init {
        Messenger.getDefault().register(
            this, Constants.MessengerToken.TOKEN_PAYMENT, PaymentItemModel::class.java
        ) { isSelected.set(false) }
    }

    val select = BindingCommand<BindingAction>(BindingAction {
        Messenger.getDefault().send(this, Constants.MessengerToken.TOKEN_PAYMENT)
        isSelected.set(true)
        viewModel.paymentTypeObservableField.set(type)
    })
}